package com.xuchaotong.seria;

import java.io.*;

public class SeriaTest {

    public static void main(String[] args) {
        AbleSeriObject obj = new AbleSeriObject();
        obj.setName("Ryan");
        obj.setGender("male");

        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream("template"));
            oos.writeObject(obj);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(oos != null){
                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
//        AbleSeriObject.age = 18;

        File file = new File("template");
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new FileInputStream(file));
            AbleSeriObject seriObject = (AbleSeriObject) ois.readObject();
            System.out.println(seriObject);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            if(ois != null){
                try {
                    ois.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
